$(function(){
	//$('#changePwd .content .alert').hide();
	$('#alertdiv').hide();
	$('#alertdiv').savehandle({
		fieldMap:{oldPwd:"原密码",password:"新密码",password2:"确认密码"},
		successMsg: '密码修改成功！',
		failMsg: '密码修改失败！错误：',
		success: successCallBack
	});
});

/**
 *密码重置成功回调
 */
function successCallBack(){
	location.href = "/fw/login/decision.action";
}

/**
 * 提交密码信息
 */
function submitPwd() {
	var oldPwd = $('#oldPwd').val();
	var password = $('#password').val();
	var password2 = $('#password2').val();
	if(oldPwd == password){
		$('#alertdiv').savehandle('setmsg',{msg:'新密码不能与旧密码相同，请重新输入!'});
		$('#password').focus();
		return;
	}
	if(password != password2){
		$('#alertdiv').savehandle('setmsg',{msg:'新密码与确认密码不同!'});
		$('#password').focus();
		return;
	}
	
	if(!$('#changePwd #changePwdForm').validate()){
		$('#alertdiv').savehandle('setmsg',{msg:'请完善输入信息!',timer:2000});
		return;
	}
	
	$.getJSON(
		'/fw/user/user_changePwd.action',
		{
			oldPwd:oldPwd,
			password:password
		},
		function(data){
			if(data && data.success){
				$.parseJSON(data);
				$('#alertdiv').savehandle('handle',data,2000);
			}else{
				$('#alertdiv').savehandle('setmsg',{msg:'重置密码失败!',timer:2000});
			}
			
		}
	)
}

/**
 * 重置表单信息
 */
function resetpwd(){
	$('form')[0].reset();
}